﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Contracts;
using System.Data.SqlClient;
using DALEF;
using System.Configuration;
using System.Data;
using Model;



namespace Services
{
    public class ProjectBService : IProjectBService
    {
        private projectbEntities _connectObject;

        private DALEFOperation _dalOperation;

        public ProjectBService()
        {
            _connectObject = new projectbEntities(ConfigurationManager.ConnectionStrings["projectbEntities"].ConnectionString);
            _dalOperation = new DALEFOperation(_connectObject);

        }

        public List<Model.Department> GetAllDepartment()
        {
            List<DALEF.Department> efDepartment = _dalOperation.GetAllDepartment();
            List<Model.Department> modelDepartment = new List<Model.Department>();
            modelDepartment = ModelTranslator.DepartmentEFtoDepartment(efDepartment);

           
            return modelDepartment;
        }


        public List<Model.Department> GetDepartment(Model.Department departmentInstance)
        {
            List<DALEF.Department> efDepartment = new List<DALEF.Department>();
            List<Model.Department> modelDepartment = new List<Model.Department>();
            modelDepartment.Add(departmentInstance);
            efDepartment = ModelTranslator.DepartmenttoDepartmentEF(modelDepartment);
            DALEF.Department t = efDepartment[0];
            efDepartment.Clear();
            efDepartment = _dalOperation.GetDepartment(t);
            modelDepartment = ModelTranslator.DepartmentEFtoDepartment(efDepartment);

           
            return modelDepartment;
        }


        public bool InsertDepartment(Model.Department departmentInstance)
        {
            try
            {
                List<DALEF.Department> efDepartment = new List<DALEF.Department>();
                List<Model.Department> modelDepartment = new List<Model.Department>();
                modelDepartment.Add(departmentInstance);
                efDepartment = ModelTranslator.DepartmenttoDepartmentEF(modelDepartment);
                _dalOperation.InsertDepartment(efDepartment[0]);
                return true;
            }

            catch (Exception e)
            {
                return false;
            }
        }


        public bool DeleteDepartment(Model.Department departmentInstance)
        {
            try
            {
                List<DALEF.Department> efDepartment = new List<DALEF.Department>();
                List<Model.Department> modelDepartment = new List<Model.Department>();
                modelDepartment.Add(departmentInstance);
                efDepartment = ModelTranslator.DepartmenttoDepartmentEF(modelDepartment);
                _dalOperation.DeleteDepartment(efDepartment[0]);
                return true;
            }
            catch (Exception e)
            {
                return false;
            }
        }


        public bool UpdateDepartment(Model.Department departmentInstance)
        {
            try
            {
                List<DALEF.Department> efDepartment = new List<DALEF.Department>();
                List<Model.Department> modelDepartment = new List<Model.Department>();
                modelDepartment.Add(departmentInstance);
                efDepartment = ModelTranslator.DepartmenttoDepartmentEF(modelDepartment);
                _dalOperation.UpdateDepartment(efDepartment[0]);
                return true;
            }
            catch (Exception e)
            {
                return false;
            }
        }



        //Operation for Teacher

        public List<Model.Teacher> GetAllTeacher()
        {
            List<DALEF.Teacher> efTeacher = _dalOperation.GetAllTeacher();
            List<Model.Teacher> modelTeacher = new List<Model.Teacher>();
            modelTeacher = ModelTranslator.TeacherEFtoTeacher(efTeacher);

            
            return modelTeacher;
        }


        public List<Model.Teacher> GetTeacher(Model.Teacher teacherInstance)
        {
            List<DALEF.Teacher> efTeacher = new List<DALEF.Teacher>();
            List<Model.Teacher> modelTeacher = new List<Model.Teacher>();
            modelTeacher.Add(teacherInstance);
            efTeacher = ModelTranslator.TeachertoTeacherEF(modelTeacher);
            DALEF.Teacher t = efTeacher[0];
            efTeacher.Clear();
            efTeacher = _dalOperation.GetTeacher(t);
            modelTeacher = ModelTranslator.TeacherEFtoTeacher(efTeacher);

            return modelTeacher;
        }


        public bool InsertTeacher(Model.Teacher teacherInstance)
        {
            try
            {
                List<DALEF.Teacher> efTeacher = new List<DALEF.Teacher>();
                List<Model.Teacher> modelTeacher = new List<Model.Teacher>();
                modelTeacher.Add(teacherInstance);
                efTeacher = ModelTranslator.TeachertoTeacherEF(modelTeacher);
                _dalOperation.InsertTeacher(efTeacher[0]);
                return true;
            }
            catch (Exception e)
            {
                return false;
            }
        }


        public bool DeleteTeacher(Model.Teacher teacherInstance)
        {
            try
            {
                List<DALEF.Teacher> efTeacher = new List<DALEF.Teacher>();
                List<Model.Teacher> modelTeacher = new List<Model.Teacher>();
                modelTeacher.Add(teacherInstance);
                efTeacher = ModelTranslator.TeachertoTeacherEF(modelTeacher);
                _dalOperation.DeleteTeacher(efTeacher[0]);
                return true;
            }
            catch (Exception e)
            {
                return false;
            }
        }


        public bool UpdateTeacher(Model.Teacher teacherInstance)
        {
            try
            {
                List<DALEF.Teacher> efTeacher = new List<DALEF.Teacher>();
                List<Model.Teacher> modelTeacher = new List<Model.Teacher>();
                modelTeacher.Add(teacherInstance);
                efTeacher = ModelTranslator.TeachertoTeacherEF(modelTeacher);
                _dalOperation.UpdateTeacher(efTeacher[0]);
                return true;
            }
            catch (Exception e)
            {
                return false;
            }
        }
    }
}
